//
//  HCSSView.m
//  Aierle
//
//  Created by WillyZhao on 2017/6/1.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCSSView.h"

#import "HCSSCollectionViewCell.h"


@interface HCSSView () <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout> {
    NSArray *arr_images;
    NSArray *arr_texts;
}

@end

@implementation HCSSView


-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubViewsss:frame];
    }
    return self;
}

-(void)initializeSubViewsss:(CGRect)frame {
    
    //数据源初始化
    arr_texts = @[@"儿童乐园",@"婴童SPA馆",@"水系乐园",@"婴童用品"];
    arr_images = @[[UIImage imageNamed:@"儿童乐园"],[UIImage imageNamed:@"婴童SPA馆"],[UIImage imageNamed:@"水系乐园"],[UIImage imageNamed:@"婴童用品"]];
    
    //试图初始化
    
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    self.collectionView_ = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) collectionViewLayout:flow];
    self.collectionView_.backgroundColor = [UIColor whiteColor];
    flow.minimumInteritemSpacing = (frame.size.width - 70*5)/8.0;
    flow.minimumLineSpacing = 0;
    self.collectionView_.delegate = self;
    self.collectionView_.dataSource = self;
    self.collectionView_.scrollEnabled = NO;
    [self addSubview:self.collectionView_];
    
    [self.collectionView_ registerNib:[UINib nibWithNibName:@"HCSSCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"ssccell"];
    
}

#pragma mark UICollectionDelgate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(YBKAdaptiveW(70), YBKAdaptiveH(65));
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HCSSCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ssccell" forIndexPath:indexPath];
    if (!cell) {
        
        cell = [[HCSSCollectionViewCell alloc] initWithFrame:CGRectZero];
    }
    [cell cellModelImages:arr_images texts:arr_texts indexPath:indexPath];
    return cell;
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    
    return UIEdgeInsetsMake(YBKAdaptiveH(5), 10, 0, 10);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    if (self.delegate && [self.delegate respondsToSelector:@selector(hcSSViewClicked:)]) {
        [self.delegate hcSSViewClicked:indexPath];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
